<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>够达平台管理系统</title>

    <link href="${ctx}/css/cms/common/assets/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="${ctx}/css/cms/common/assets/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="${ctx}/css/cms/common/assets/css/font.css"/>
    <link rel="stylesheet" href="${ctx}/css/cms/common/assets/css/ace.min.css"/>
    <script type="text/javascript" src="${ctx}/js/common/jquery-1.8.0.js"></script>
    <script type="text/javascript" src="${ctx}/js/cms/index.js"></script>
    <script type="text/javascript">
        $(function () {
            //设置登录名
            if ($.cookie("adminId")) {
                var adminName = "";
                if ($.cookie("adminName")) {
                    adminName = $.cookie("adminName");
                }
                $("#loginName").html(adminName);
            }

            //退出登录
            $("#logout").on("click", function (e) {
                $.ajax({
                    type: "get",
                    url: "${ctx}/systemUser/logout",
                    //data : $('#inputForm').serialize(),
                    dataType: "json",
                    success: function (json) {
                        if ("1" === json["result"]) {
                            alert("退出成功!");
                            window.location.href = "${ctx}/index";
                        } else {
                            alert("退出失败!");
                        }
                    },
                    error: function (json) {
                        alert("退出失败!");
                    }
                });
                e.preventDefault;
            });

            var iframe = document.getElementById("contIframe");

            window.setInterval(function () {
                try {
                    iframe.height = iframe.contentWindow.document.documentElement.scrollHeight;
                } catch (ex) {
                }
            }, 200);

        });

        function loadChildren(functionId){
            $.ajax({
                type: "get",
                url: "${ctx}/systemFunction/getChildren",
                data : "parentId=" + functionId,
                dataType: "json",
                success: function (json) {
                    var functions = json.data;
                    var rootNode = $("#rootNode"+functionId);
                    var htmlText = '<ul class="submenu">';
                    for(i in functions){
                        var functionName = functions[i].functionName;
                        var functionUrl = functions[i].functionUrl;
                        var childFunctionId = functions[i].functionId;
                        if('' === functionUrl || null === functionUrl || undefined === functionUrl){
                            htmlText += '<li class="active" id="rootNode' + childFunctionId + '"><a class="dropdown-toggle" onclick="loadChildren(' + childFunctionId + ')"><i class="icon-double-angle-right"></i>' + functionName + '</a></li>';
                        }else{
                            htmlText += '<li><a onclick="activeFrame($(this))" iframeSrc="' + functionUrl  + '"><i class="icon-double-angle-right"></i>' + functionName + '</a></li>';
                        }
                    }
                    htmlText += '</ul>';
                    rootNode.append(htmlText);
                }
            });
            $("#rootNode"+functionId).children(".dropdown-toggle").removeAttr("onclick");
        }

        function activeFrame(element){
            if(element.attr('iframeSrc')){
                $('.page-header h1 strong').text(element.text());
                $("#contIframe").attr('src',element.attr('iframeSrc'));
            }
        }
    </script>
</head>

<body>
    <div class="navbar navbar-default" id="navbar">

        <div class="navbar-container" id="navbar-container">
            <div class="navbar-header pull-left">
                <a href="#" class="navbar-brand">
                    <%--<img src="${ctx}/images/cms/logo.png" alt=""/>--%>
                    <small>
                        <strong>够达平台管理系统</strong>
                    </small>
                </a><!-- /.brand -->
            </div>
            <!-- /.navbar-header -->

            <div class="navbar-header pull-right" role="navigation">
                <ul class="nav ace-nav">


                    <li class="light-blue">
                        <a data-toggle="dropdown" href="#" class="dropdown-toggle">
                            <img class="nav-user-photo" src="${ctx}/css/cms/common/assets/avatars/user.jpg"
                                 alt="Jason's Photo">
                                    <span class="user-info">
                                        <small>Welcome,</small>
                                        <small id="loginName">Jason</small>
                                    </span>

                            <i class="icon-caret-down"></i>
                        </a>

                        <ul class="user-menu pull-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close">


                            <li class="divider"></li>

                            <li>
                                <a href="#" id="logout">
                                    <i class="icon-off"></i>
                                    退出
                                </a>
                            </li>
                        </ul>
                    </li>
                </ul>
                <!-- /.ace-nav -->
            </div>
        </div>
        <!-- /.container -->
    </div>

    <div class="main-container" id="main-container"></div>

    <div class="main-container-inner">
        <a class="menu-toggler" id="menu-toggler" href="#">
            <span class="menu-text"></span>
        </a>

        <div class="sidebar" id="sidebar">
            <div class="sidebar-shortcuts" id="sidebar-shortcuts">
                <div class="sidebar-shortcuts-large" id="sidebar-shortcuts-large">
                    <button class="btn btn-success">
                        <i class="icon-signal"></i>
                    </button>

                    <button class="btn btn-info">
                        <i class="icon-pencil"></i>
                    </button>

                    <button class="btn btn-warning">
                        <i class="icon-group"></i>
                    </button>

                    <button class="btn btn-danger">
                        <i class="icon-cogs"></i>
                    </button>
                </div>

                <div class="sidebar-shortcuts-mini" id="sidebar-shortcuts-mini">
                    <span class="btn btn-success"></span>

                    <span class="btn btn-info"></span>

                    <span class="btn btn-warning"></span>

                    <span class="btn btn-danger"></span>
                </div>
            </div>
        <!-- #sidebar-shortcuts -->

        <ul class="nav nav-list" id="navList">
            <c:forEach var="entity" items="${privileges}">
                <li id="rootNode${entity.functionId}">
                    <a class="dropdown-toggle" onclick="loadChildren(${entity.functionId})" >
                        <i class="icon-list"></i>
                        <span class="menu-text">${entity.functionName}</span>

                        <b class="arrow icon-angle-down"></b>
                    </a>
                </li>
            </c:forEach>
        </ul>
        <!-- /.nav-list -->

        <div class="sidebar-collapse" id="sidebar-collapse">
            <i class="icon-double-angle-left" data-icon1="icon-double-angle-left"
               data-icon2="icon-double-angle-right"></i>
        </div>

        </div>

        <div class="main-content" id="rightContent">

            <div class="page-content">
                <div class="page-header">
                    <h1>
                        <strong>首页</strong>

                    </h1>
                </div>

                <div class="row">

                    <iframe src="" id="contIframe" frameborder="0" scrolling="no"></iframe>
                </div>
            </div>
        </div>

    </div>

</body>
</html>

